package com.tkwayne.ftpclient.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;

/**
 * @author wayne
 * @description 
 * @date 2019/7/20 16:47
 */
public class ByteUtil {

	private static Logger logger = LoggerFactory.getLogger(ByteUtil.class);

	public static byte[] inputStreamToByteArray(InputStream in)  {
		try {
			ByteArrayOutputStream out = new ByteArrayOutputStream();
			byte[] buffer = new byte[1024 * 4];
			int n = 0;
			while ((n = in.read(buffer)) > 0) {
				out.write(buffer, 0, n);
			}
			return out.toByteArray();
		} catch (Exception e) {
			logger.error("ftpClient transfer byte error");
			return null;
		}  
	 }
}
